
class PasswordException extends Exception{
    public PasswordException(String message){
        super(message);
    }
}
class UseNameException extends Exception{
    public UseNameException(String message){
        super(message);
    }
}
public class Test {
    private String userName="admin";
    private String password="123456";
    public static void loginInfo(String userName,String password) throws UseNameException,PasswordException{
        if(!userName.equals(userName)){
            throw new UseNameException("用户名错误！");
        }if(!password.equals(password)){
            throw new PasswordException("用户名错误！");
        }System.out.println("登陆成功");
    }
    public static void main(String[]args){
        try{
            loginInfo("admin","1234");
        }catch(UseNameException e){
            e.printStackTrace();
        }catch(PasswordException e){
            e.printStackTrace();
        }
    }
}


/*import java.util.Scanner;
class UserPasswordException extends Exception {
    public UserPasswordException(String message) {
        super(message);
    }
}
class UserNameException extends Exception {
    public UserNameException(String message) {
        super(message);
    }
}
public class Test {
    private String name = "zhangsan";
    private String password = "123456";
    public static void loginException(String name1, String password1) throws UserNameException, UserPasswordException{
        if(!name1.equals(name)) {
            throw new UserNameException("用户名错误！");
        }
        if(!password1.equals(password)) {
            throw new UserNameException("密码错误！");
        }
        System.out.println("登陆成功！");
    }
    public static void main(String[] args) {
        while(true) {
            Scanner scanner = new Scanner(System.in);
            String name1 = scanner.nextLine();
            String password1 = scanner.nextLine();
            try {
                loginException(name1, password1);
            } catch (UserNameException e) {
                e.printStackTrace();
            } catch (UserPasswordException e) {
                e.printStackTrace();
            }
        }
    }
}*/

